package com.cn.gmall.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cn.gmall.common.result.Result;
import com.cn.gmall.model.base.BaseEntity;
import com.cn.gmall.model.product.BaseTrademark;
import com.cn.gmall.product.service.BaseTrademarkService;

import org.apache.naming.factory.ResourceLinkFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {
    @Autowired
    private BaseTrademarkService baseTrademarkService;

    /**
     * 品牌 分页列表
     *
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/{page}/{limit}")
    public Result baseTrademarkPage(@PathVariable Long page, @PathVariable Long limit) {
        Page<BaseTrademark> tra = new Page<>(page, limit);

        IPage<BaseTrademark> baseTrademarkIPage = baseTrademarkService.baseTrademarkPage(tra);
        return Result.ok(baseTrademarkIPage);
    }

    /**
     * 根据品牌Id 获取品牌对象
     *
     * @return
     */
    @GetMapping("/get/{id}")
    public Result getBaseTradeMarkById(@PathVariable Long id) {
        BaseTrademark baseTrademark = baseTrademarkService.getBaseTradeMarkById(id);
        if (baseTrademark == null) {
            return Result.fail("未查询到相关数据");
        }
        return Result.ok(baseTrademark);
    }

    /**
     * 保存 baseTrademark
     *
     * @return
     */

    @PostMapping("/save")
    public Result save(@RequestBody BaseTrademark baseTrademark) {

        baseTrademarkService.saveBaseTrademark(baseTrademark);
        return Result.ok();
    }

    /**
     * 修改 baseTrademark
     *
     * @param baseTrademark
     * @return
     */
    @PutMapping("/update")
    public Result updateBaseTrademark(@RequestBody BaseTrademark baseTrademark) {
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    /**
     * 删除 baseTrademark
     * @param id
     * @return
     */
    @DeleteMapping("/remove/{id}")
    public Result removeById(@PathVariable Long id) {
        baseTrademarkService.removeById(id);
        return Result.ok();
    }
}
